/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Vista;

import Controlador.Busqueda;
import Controlador.Factory;
import Modelo.*;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Diana & Ram
 */
public class IUMedico extends javax.swing.JFrame {
    private static Medico medico;
    DefaultListModel lista=new DefaultListModel();
    DefaultListModel listainicial=new DefaultListModel();
    DefaultListModel listaMedicamentos=new DefaultListModel();
    DefaultListModel listaAlergias=new DefaultListModel();
    DefaultListModel listaMedicamentosA=new DefaultListModel();
    ArrayList<Paciente> p;
    ArrayList<Paciente> pi=Factory.getInstance().getPacientes();
    
    /**
     * Creates new form Medico
     */
    public IUMedico(Medico medico) {
        initComponents();
        Date d=new Date();
        this.medico=medico;
        this.setLocationRelativeTo(null);
        this.setTitle("Bienvenido: "+medico.getNombre());
        this.lblNombreMedico.setText("Bienvenido: "+medico.getNombre());
        this.lblFecha.setText("Inicio de sesion: "+d.toLocaleString());
        LlenarListaPacientes();
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        
    }
    
    public void LlenarListaPacientes(){
    for(int i=0;i<pi.size();i++)
            {
                listainicial.addElement(pi.get(i).getNombre()+" "+pi.get(i).getApellidoPaterno()+" "+pi.get(i).getApellidoMaterno());
            }
        lstPacientes.setModel(listainicial);
    
    }
    
     /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tabPaciente = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        tfBusqueda = new javax.swing.JTextField();
        btnBuscar = new javax.swing.JButton();
        jScrollPane8 = new javax.swing.JScrollPane();
        lstPacientes = new javax.swing.JList();
        jLabel1 = new javax.swing.JLabel();
        panPaciente = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        tfNombre = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        tfSexo = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        tfSangre = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        tfAPaterno = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        tfAMaterno = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        lstAlergias = new javax.swing.JList();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        tfEdad = new javax.swing.JTextField();
        tfEstatura = new javax.swing.JTextField();
        tfPeso = new javax.swing.JTextField();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel17 = new javax.swing.JLabel();
        tfPresion = new javax.swing.JTextField();
        chDiabetes = new javax.swing.JCheckBox();
        chHipertencion = new javax.swing.JCheckBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        taPadecimientos = new javax.swing.JTextArea();
        jLabel18 = new javax.swing.JLabel();
        lblImagen = new javax.swing.JLabel();
        panDiagnostico = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane6 = new javax.swing.JScrollPane();
        txtDiagnostico = new javax.swing.JTextArea();
        paneReceta = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        jScrollPane7 = new javax.swing.JScrollPane();
        txtReceta = new javax.swing.JTextArea();
        jLabel14 = new javax.swing.JLabel();
        jScrollPane5 = new javax.swing.JScrollPane();
        lstSubstacias = new javax.swing.JList();
        tfCantidad = new javax.swing.JTextField();
        tfCada = new javax.swing.JTextField();
        tfDurante = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        btnTerminarConsulta = new javax.swing.JButton();
        btnAddMedicamento = new javax.swing.JButton();
        lblFecha = new javax.swing.JLabel();
        lblNombreMedico = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMaximumSize(new java.awt.Dimension(900, 390));
        setMinimumSize(new java.awt.Dimension(900, 390));
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        tfBusqueda.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tfBusquedaKeyPressed(evt);
            }
        });

        btnBuscar.setText("Buscar");
        btnBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarActionPerformed(evt);
            }
        });

        lstPacientes.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lstPacientesMouseClicked(evt);
            }
        });
        jScrollPane8.setViewportView(lstPacientes);

        jLabel1.setText("Nombre:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnBuscar)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tfBusqueda, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane8, javax.swing.GroupLayout.PREFERRED_SIZE, 237, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(225, 225, 225))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane8, javax.swing.GroupLayout.PREFERRED_SIZE, 259, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tfBusqueda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1))
                        .addGap(18, 18, 18)
                        .addComponent(btnBuscar)))
                .addContainerGap(55, Short.MAX_VALUE))
        );

        tabPaciente.addTab("Citas", jPanel1);

        jLabel3.setText("Nombre:");

        tfNombre.setEditable(false);
        tfNombre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfNombreActionPerformed(evt);
            }
        });

        jLabel4.setText("Sexo:");

        tfSexo.setEditable(false);

        jLabel5.setText("Tipo de sangre:");

        tfSangre.setEditable(false);

        jLabel6.setText("Apellido Paterno:");

        tfAPaterno.setEditable(false);
        tfAPaterno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfAPaternoActionPerformed(evt);
            }
        });

        jLabel7.setText("Apellido Materno:");

        tfAMaterno.setEditable(false);

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Historial Clinico"));

        jLabel8.setText("Edad:");

        jLabel9.setText("Estatura:");

        jLabel10.setText("Peso:");

        jScrollPane2.setViewportView(lstAlergias);

        jLabel11.setText("Padecimientos:");

        jLabel12.setText("Enfermedades Her.");

        tfEdad.setEditable(false);

        tfEstatura.setEditable(false);
        tfEstatura.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfEstaturaActionPerformed(evt);
            }
        });

        jSeparator1.setBackground(new java.awt.Color(0, 0, 0));
        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);

        jLabel17.setText("Presion:");

        chDiabetes.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        chDiabetes.setText("Diabetes");

        chHipertencion.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        chHipertencion.setText("Hipertencion");

        taPadecimientos.setColumns(20);
        taPadecimientos.setRows(5);
        jScrollPane1.setViewportView(taPadecimientos);

        jLabel18.setText("Alergias:");

        lblImagen.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        lblImagen.setMaximumSize(new java.awt.Dimension(131, 111));
        lblImagen.setMinimumSize(new java.awt.Dimension(131, 111));

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jLabel11)
                                .addGap(139, 139, 139)
                                .addComponent(jLabel12))
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(jPanel4Layout.createSequentialGroup()
                                        .addGap(14, 14, 14)
                                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(jPanel4Layout.createSequentialGroup()
                                                .addComponent(jLabel10)
                                                .addGap(18, 18, 18)
                                                .addComponent(tfPeso, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addGroup(jPanel4Layout.createSequentialGroup()
                                                .addComponent(jLabel8)
                                                .addGap(18, 18, 18)
                                                .addComponent(tfEdad, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                    .addGroup(jPanel4Layout.createSequentialGroup()
                                        .addComponent(jLabel9)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(tfEstatura, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(30, 30, 30)
                                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel17)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(tfPresion, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(84, 84, 84)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel18)
                            .addComponent(lblImagen, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(49, 49, 49)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(chHipertencion)
                            .addComponent(chDiabetes))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 76, Short.MAX_VALUE)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(50, 50, 50))))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGap(5, 5, 5)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel17)
                                    .addComponent(tfPresion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(lblImagen, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(27, 27, 27)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel11)
                            .addComponent(jLabel12)
                            .addComponent(jLabel18)))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(tfEdad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(12, 12, 12)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9)
                            .addComponent(tfEstatura, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(20, 20, 20)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel10)
                            .addComponent(tfPeso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                        .addGap(37, 37, 37))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(chDiabetes)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(chHipertencion))
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
        );

        javax.swing.GroupLayout panPacienteLayout = new javax.swing.GroupLayout(panPaciente);
        panPaciente.setLayout(panPacienteLayout);
        panPacienteLayout.setHorizontalGroup(
            panPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panPacienteLayout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(panPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(panPacienteLayout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tfNombre))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panPacienteLayout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tfAMaterno))
                    .addGroup(panPacienteLayout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tfAPaterno, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panPacienteLayout.createSequentialGroup()
                        .addGroup(panPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, panPacienteLayout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addGap(18, 18, 18)
                                .addComponent(tfSexo))
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(tfSangre, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 60, Short.MAX_VALUE)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18))
        );
        panPacienteLayout.setVerticalGroup(
            panPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panPacienteLayout.createSequentialGroup()
                .addGap(37, 37, 37)
                .addGroup(panPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tfAPaterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addGap(8, 8, 8)
                .addGroup(panPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(tfAMaterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(tfNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(panPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(tfSexo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(panPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(tfSangre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(panPacienteLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        tabPaciente.addTab("Paciente actual", panPaciente);

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Diagnostico"));

        txtDiagnostico.setColumns(20);
        txtDiagnostico.setRows(5);
        jScrollPane6.setViewportView(txtDiagnostico);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 842, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout panDiagnosticoLayout = new javax.swing.GroupLayout(panDiagnostico);
        panDiagnostico.setLayout(panDiagnosticoLayout);
        panDiagnosticoLayout.setHorizontalGroup(
            panDiagnosticoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panDiagnosticoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        panDiagnosticoLayout.setVerticalGroup(
            panDiagnosticoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panDiagnosticoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(57, Short.MAX_VALUE))
        );

        tabPaciente.addTab("Diagnostico", panDiagnostico);

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Receta"));

        txtReceta.setColumns(20);
        txtReceta.setRows(5);
        jScrollPane7.setViewportView(txtReceta);

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane7, javax.swing.GroupLayout.DEFAULT_SIZE, 530, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane7, javax.swing.GroupLayout.DEFAULT_SIZE, 280, Short.MAX_VALUE)
        );

        jLabel14.setText("Substancias para recetar al Paciente:");

        lstSubstacias.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lstSubstaciasMouseClicked(evt);
            }
        });
        jScrollPane5.setViewportView(lstSubstacias);

        jLabel13.setText("Cantidad:");

        jLabel15.setText("Cada:");

        jLabel16.setText("Durante:");

        btnTerminarConsulta.setText("Terminar Consulta");

        btnAddMedicamento.setText("Agregar Medicamento");
        btnAddMedicamento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddMedicamentoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout paneRecetaLayout = new javax.swing.GroupLayout(paneReceta);
        paneReceta.setLayout(paneRecetaLayout);
        paneRecetaLayout.setHorizontalGroup(
            paneRecetaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(paneRecetaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(paneRecetaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(paneRecetaLayout.createSequentialGroup()
                        .addGap(41, 41, 41)
                        .addGroup(paneRecetaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(paneRecetaLayout.createSequentialGroup()
                                .addGroup(paneRecetaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel13)
                                    .addComponent(jLabel15)
                                    .addComponent(jLabel16))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(paneRecetaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(tfCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(tfCada, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(tfDurante, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(25, 25, 25)
                        .addGroup(paneRecetaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnAddMedicamento)
                            .addComponent(btnTerminarConsulta)))
                    .addGroup(paneRecetaLayout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jLabel14)))
                .addGap(9, 9, 9))
        );
        paneRecetaLayout.setVerticalGroup(
            paneRecetaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(paneRecetaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(paneRecetaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(paneRecetaLayout.createSequentialGroup()
                        .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(paneRecetaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, paneRecetaLayout.createSequentialGroup()
                                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, paneRecetaLayout.createSequentialGroup()
                                .addComponent(btnAddMedicamento)
                                .addGap(1, 1, 1)))
                        .addGroup(paneRecetaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tfCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel13))
                        .addGap(18, 18, 18)
                        .addGroup(paneRecetaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tfCada, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel15))
                        .addGap(18, 18, 18)
                        .addGroup(paneRecetaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tfDurante, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel16)
                            .addComponent(btnTerminarConsulta))
                        .addGap(31, 31, 31))
                    .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        tabPaciente.addTab("Recetar", paneReceta);

        lblFecha.setText("02:20 p.m");

        lblNombreMedico.setFont(new java.awt.Font("Century Gothic", 1, 12)); // NOI18N
        lblNombreMedico.setText("Bienvenido: Juan López");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(tabPaciente)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(lblNombreMedico)
                .addGap(42, 42, 42)
                .addComponent(lblFecha)
                .addGap(50, 50, 50))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblFecha)
                    .addComponent(lblNombreMedico))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(tabPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, 349, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tfNombreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfNombreActionPerformed

// TODO add your handling code here:
    }//GEN-LAST:event_tfNombreActionPerformed

    private void tfAPaternoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfAPaternoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tfAPaternoActionPerformed

    private void tfEstaturaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfEstaturaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tfEstaturaActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        new LogIn().setVisible(true);
// TODO add your handling code here:
    }//GEN-LAST:event_formWindowClosing

    private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarActionPerformed
        borrarHistorial();
        p=Busqueda.buscar(tfBusqueda.getText());
        lista=new DefaultListModel();
        if(p!=null){
            for(int i=0;i<p.size();i++)
            {
                lista.addElement(p.get(i).getNombre()+" "+p.get(i).getApellidoPaterno()+" "+p.get(i).getApellidoMaterno());
            }
            lstPacientes.setModel(lista);
            tfBusqueda.setText("");
        }
        else{
            JOptionPane.showMessageDialog(this, "No se encontro ningun paciente con ese Nombre");
            tfBusqueda.setText("");
            lstPacientes.setModel(listainicial);
        }
        
        
        
        // TODO add your handling code here:
    }//GEN-LAST:event_btnBuscarActionPerformed

    public void llenarHistorial(int i){
        if(p!=null){
            tfAPaterno.setText(p.get(i).getApellidoPaterno());
            tfAMaterno.setText(p.get(i).getApellidoMaterno());
            tfNombre.setText(p.get(i).getNombre());
            tfEdad.setText(p.get(i).getEdad()+"");
            tfPeso.setText(p.get(i).getPeso()+"");
            tfSangre.setText(p.get(i).getTipoSangre());
            tfEstatura.setText(p.get(i).getEstatura()+"");
            tfPresion.setText(p.get(i).getHistorialMedico().getPresion());
            chDiabetes.setSelected(pi.get(i).getHistorialMedico().isFamiliaDiabetes());
            chHipertencion.setSelected(p.get(i).getHistorialMedico().isFamiliaHipertension());
            taPadecimientos.setText(p.get(i).getHistorialMedico().getPadecimientos());
            listaAlergias=new DefaultListModel();
            for(int j=0;j<p.get(i).getHistorialMedico().getAlergias().size();j++)
            {
                listaAlergias.addElement(p.get(i).getHistorialMedico().getAlergias().get(j));
            }
            lstAlergias.setModel(listaAlergias);
            listaMedicamentos=new DefaultListModel();
            for(int j=0;j<Factory.getInstance().getMedicamentos().size();j++)
            {
                listaMedicamentos.addElement(Factory.getInstance().getMedicamentos().get(j).getNombre());
            }
            /*lstSubstacias.setModel(listaMedicamentos);
            listaMedicamentosA=new DefaultListModel();
            for(int j=0;j<p.get(i).getHistorialMedico().ge)*/
            lblImagen.setIcon(new ImageIcon(Factory.getInstance().getPacientes().get(i).getFoto()));
            lblImagen.setText(Factory.getInstance().getPacientes().get(i).getFoto());
                
            
            
        
        }
        else
        {
            tfAPaterno.setText(pi.get(i).getApellidoPaterno());
            tfAMaterno.setText(pi.get(i).getApellidoMaterno());
            tfNombre.setText(pi.get(i).getNombre());
            tfEdad.setText(pi.get(i).getEdad()+"");
            tfPeso.setText(pi.get(i).getPeso()+"");
            tfSangre.setText(pi.get(i).getTipoSangre());
            tfEstatura.setText(pi.get(i).getEstatura()+"");
            tfPresion.setText(pi.get(i).getHistorialMedico().getPresion());
            chDiabetes.setSelected(pi.get(i).getHistorialMedico().isFamiliaDiabetes());
            chHipertencion.setSelected(pi.get(i).getHistorialMedico().isFamiliaHipertension());
            taPadecimientos.setText(pi.get(i).getHistorialMedico().getPadecimientos());
            listaAlergias=new DefaultListModel();
            for(int j=0;j<pi.get(i).getHistorialMedico().getAlergias().size();j++)
            {
                listaAlergias.addElement(pi.get(i).getHistorialMedico().getAlergias().get(j));
            }
        lstAlergias.setModel(listaAlergias);
        }
        for(int j=0;j<Factory.getInstance().getMedicamentos().size();j++)
            {
                listaMedicamentos.addElement(Factory.getInstance().getMedicamentos().get(j).getNombre());
            }
            lstSubstacias.setModel(listaMedicamentos);
        lblImagen.setIcon(new ImageIcon(Factory.getInstance().getPacientes().get(i).getFoto()));
            lblImagen.setText(Factory.getInstance().getPacientes().get(i).getFoto());
    }
    public void borrarHistorial(){
        tfNombre.setText("");
        tfEdad.setText("");
        tfPeso.setText("");
        tfSangre.setText("");
        tfEstatura.setText("");
        tfAMaterno.setText("");
        tfSexo.setText("");
        tfAPaterno.setText("");
    }
    private void lstPacientesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lstPacientesMouseClicked
       
        int i=lstPacientes.getSelectedIndex();
        if(i>=0){
        llenarHistorial(i);
        tabPaciente.setSelectedIndex(1);}
        else borrarHistorial();
       
        // TODO add your handling code here:
    }//GEN-LAST:event_lstPacientesMouseClicked

    private void tfBusquedaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfBusquedaKeyPressed

    }//GEN-LAST:event_tfBusquedaKeyPressed

    private void lstSubstaciasMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lstSubstaciasMouseClicked

        
        // TODO add your handling code here:
    }//GEN-LAST:event_lstSubstaciasMouseClicked

    private void btnAddMedicamentoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddMedicamentoActionPerformed
 int i=lstSubstacias.getSelectedIndex();
        if(i>=0){
            
            txtReceta.setText(txtReceta.getText()+tfCantidad.getText()+" "+lstSubstacias.getSelectedValue().toString()+" cada "+tfCada.getText()+"hrs durante "+tfDurante.getText()+" dias\n");
            tfCantidad.setText("");
            tfCada.setText("");
            tfDurante.setText("");
        }        
// TODO add your handling code here:
    }//GEN-LAST:event_btnAddMedicamentoActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(IUMedico.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(IUMedico.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(IUMedico.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(IUMedico.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new IUMedico(medico).setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAddMedicamento;
    private javax.swing.JButton btnBuscar;
    private javax.swing.JButton btnTerminarConsulta;
    private javax.swing.JCheckBox chDiabetes;
    private javax.swing.JCheckBox chHipertencion;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JScrollPane jScrollPane8;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel lblFecha;
    private javax.swing.JLabel lblImagen;
    private javax.swing.JLabel lblNombreMedico;
    private javax.swing.JList lstAlergias;
    private javax.swing.JList lstPacientes;
    private javax.swing.JList lstSubstacias;
    private javax.swing.JPanel panDiagnostico;
    private javax.swing.JPanel panPaciente;
    private javax.swing.JPanel paneReceta;
    private javax.swing.JTextArea taPadecimientos;
    private javax.swing.JTabbedPane tabPaciente;
    private javax.swing.JTextField tfAMaterno;
    private javax.swing.JTextField tfAPaterno;
    private javax.swing.JTextField tfBusqueda;
    private javax.swing.JTextField tfCada;
    private javax.swing.JTextField tfCantidad;
    private javax.swing.JTextField tfDurante;
    private javax.swing.JTextField tfEdad;
    private javax.swing.JTextField tfEstatura;
    private javax.swing.JTextField tfNombre;
    private javax.swing.JTextField tfPeso;
    private javax.swing.JTextField tfPresion;
    private javax.swing.JTextField tfSangre;
    private javax.swing.JTextField tfSexo;
    private javax.swing.JTextArea txtDiagnostico;
    private javax.swing.JTextArea txtReceta;
    // End of variables declaration//GEN-END:variables
}
